//
//  YZXNewFeatureController.swift
//  YZXWeibo
//
//  Created by 叶周翔 on 16/7/22.
//  Copyright © 2016年 叶周翔. All rights reserved.
//

import UIKit

private let itemCount = 4

class YZXNewFeatureController: UICollectionViewController {
    
    let layout = UICollectionViewFlowLayout()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //  注册一个cell
        self.collectionView?.registerClass(YZXNewFeatCell.classForCoder(), forCellWithReuseIdentifier: "cell")
        // 设置流水布局
        self.setUpLayout()
        
        
    }
    // 初始化
    init(){
        super.init(collectionViewLayout: layout)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    /**
      设置流水布局
     */
    func setUpLayout(){
        self.layout.itemSize = self.view.frame.size
        self.layout.minimumInteritemSpacing = 0
        self.layout.minimumLineSpacing = 0
        // 滚动方向
        self.layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
        self.collectionView?.pagingEnabled = true
    }
    
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return itemCount
    }
    
    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! YZXNewFeatCell
        
        cell.image = UIImage(named: "new_feature_\(indexPath.item+1)")
        cell.startBtnDidCallBack = { () -> Void in
            // 界面的跳转
            AppDelegate.jumpToOtherController(YZXTabBarController())
        }
        
        if indexPath.item == itemCount-1{
            cell.showBtn(false)
            
        }else{
            cell.showBtn(true)
        }
        
        return cell
    }
}
